﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace ChinaDynastyTours.Controls
{
    class TravelExpenseCtrl
    {
        #region 获取地接社费用信息
        /// <summary>
        /// 获取宾馆费用信息
        /// </summary>
        /// <param name="tourGroupId">所属团号</param>
        /// <returns></returns>
        internal static DataTable GetTravelExpenseData(string tourGroupId)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand;
            //根据行程计划ID，取得‘费用表’与‘宾馆预定信息’表联合数据
            string sql = string.Format(@"SELECT 
                                        e.[ExpenseID], e.[TourgroupID], e.[ProviderName], e.[Budget], 
                                        e.[Status], h.[TourGroupScheduleID],h.[City], h.[ProviderName], h.[ServiceName], h.[SinglePrice], h.[Amount], h.[ContractPath] 
                                        FROM fee_Expense e,fee_TravelOrder h 
                                        WHERE  e.TourGroupID='{0}' AND e.TypeBelong='{1}' AND e.ExpenseID=h.ExpenseID",
                                        tourGroupId, ExpenseTypeBelongEnum.地接社);

            dbCommand = db.GetSqlStringCommand(sql);

            DataSet ds = db.ExecuteDataSet(dbCommand);
            if (ds.Tables.Count > 0)
                return ds.Tables[0];
            else
                return null;
        }
        /// <summary>
        /// 删除指定费用编号的
        /// </summary>
        /// <param name="expenseId"></param>
        /// <returns></returns>
        public static int DeleteTravelExpense(int expenseId)
        {
            Database db = DatabaseFactory.CreateDatabase();

            string sql = string.Format(@"DELETE FROM fee_TravelOrder WHERE expenseid={0};
                                         DELETE FROM fee_expense WHERE  expenseid={1};",//同时删除费用和宾馆相关内容
                                         expenseId, expenseId);
            return db.ExecuteNonQuery(CommandType.Text, sql);
        }
        #endregion

    }
}
